package reader.contorller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reader.entity.Category;
import reader.service.CategoryService;
import reader.utils.ResponseUtils;

import java.util.List;

@RestController
@RequestMapping("/api/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/list")
    public ResponseUtils list(){
        ResponseUtils response = null;
        try {
            List<Category> categories = categoryService.selectCategoryAll();
            response = new ResponseUtils().put("list",categories);
        }catch (Exception e){
            e.printStackTrace();
            response = new ResponseUtils().put("error",e.getMessage());
        }
    return response;
    }


}
